package com.example.wisdomclassroomapi.domain.repository;

import com.example.wisdomclassroomapi.domain.entity.GradeLessonBindEntity;
import com.example.wisdomclassroomapi.infrastructure.mapper.GradeLessonBindMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Repository;
import javax.annotation.Resource;
import java.util.List;
/**
 * @Package: com.example.wisdomclassroomapi.domain.repository
 * @Description: <>
 * @Author: scholes
 * @CreateDate: 2022-04-18
 * @UpdateUser: scholes
 * @UpdateDate: 2022-04-18
 * @UpdateRemark: <>
 * @Version: 1.0
 */
@Repository
public class GradeLessonBindRepository {
    @Resource
    private GradeLessonBindMapper gradeLessonBindMapper;

    public void add(GradeLessonBindEntity entity) {
       gradeLessonBindMapper.insert(entity);
    }

    public GradeLessonBindEntity findById(String id) {
        return gradeLessonBindMapper.selectById(id);
    }

    public int updateById(GradeLessonBindEntity entity) {
        return gradeLessonBindMapper.updateById(entity);
    }

    public int deleteById(String id) {
        return gradeLessonBindMapper.deleteById(id);
    }

    public IPage<GradeLessonBindEntity> page(GradeLessonBindEntity entity,IPage page) {
        QueryWrapper<GradeLessonBindEntity> wrapper = new QueryWrapper<>();
            if (StringUtils.isNotBlank(entity.getGradeId())){
            wrapper.eq("grade_id",entity.getGradeId());
            }
            if (StringUtils.isNotBlank(entity.getLessonId())){
            wrapper.eq("lesson_id",entity.getLessonId());
            }
        return gradeLessonBindMapper.selectPage(page, wrapper);
    }

    public List<GradeLessonBindEntity> list(GradeLessonBindEntity entity) {
        QueryWrapper<GradeLessonBindEntity> wrapper = new QueryWrapper<>();
            if (StringUtils.isNotBlank(entity.getGradeId())){
            wrapper.eq("grade_id",entity.getGradeId());
            }
            if (StringUtils.isNotBlank(entity.getLessonId())){
            wrapper.eq("lesson_id",entity.getLessonId());
            }
        return gradeLessonBindMapper.selectList(wrapper);
    }

}